
<?php if(isset($isInsert) && $isInsert){
?>
<script>
	ajax('listContent','<?php echo $this->params['controller']?>/lists');
	closeBox('addContent','mainContent');
</script>
<?php
}
else{
?>
<fieldset>
    <legend><?php _resource('edit'. $this->params['controller']);?></legend>
<center><div id="message">&nbsp;</div><center>
<?php if($this->Session->read('message')){
	echo '<script>showMessage("addContent","'.$this->Session->read('message').'");</script>';
	$this->Session->delete('message');	
	}?>
<?php if($this->Session->read('error')){
	echo '<script>showMessage("addContent","'.$this->Session->read('error').'",1);</script>';
	$this->Session->delete('error');
}?>
    <form id="adminForm" name="adminForm" method="post" action="<?php echo $this->params['controller']?>/edit/<?php echo $this->data[$uses[0]]['id'].'/'.$locale ?>" onsubmit="onFormSubmit();return false;">
    <?php
		echo $this->Form->hidden($uses[0].'.id');		
		echo $this->Form->hidden($uses[0].'.view_order');
		echo $this->Form->hidden($uses[0].'.published');
		if($webConfig['is_multi_lang']){
			echo $this->Form->hidden($uses[0].'.defaultdescription');
		}

	?>
	<table border="0" class="form" style="width:100%">
       		<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('title') ?>
       		<?php if($webConfig['is_multi_lang']){?>
       		<img class="Tips1" title="<?php echo $listLang[$locale]?>" border="0" src="<?php echo $this->webroot.'img/backend/flag/'.$locale.'.png'?>">
       		<?php }?>
       		</td>
       		<td align="left"><?php echo $this->Form->input($uses[0].'.title',array('class'=>'input','label'=>'','size'=>60,'maxlength'=>255));?></td>           
        </tr>
         <?php if($locale!=$this->Session->read('adminLang') && $webConfig['is_multi_lang']){?>
        	<tr>
            	<td class="label" align="right" width="100px"><?php _resource('title') ?> <img class="Tips1" title="<?php echo $listLang[$this->Session->read('adminLang')]?>" border="0" src="<?php echo $this->webroot.'img/backend/flag/'.$this->Session->read('adminLang').'.png'?>"></td>
            	<td colspan="2"><?php echo $this->data[$uses[0]]['defaulttitle'] ?></td>
          	</tr>
        <?php }?>  
     

		<tr>          
       		<td class="label" align="right" width="100px">       			
       			<div style="width: 80px; height: 18px; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;float: right;">
					<span id="spanButtonPlaceholder"></span>
				</div>
       			
       		</td>
       		<td align="left">
       		<?php echo $this->Form->hidden($uses[0].'.image',array('class'=>'input','label'=>'','div'=>'','size'=>60,'maxlength'=>255,'readonly'=>'readonly'));?>
       		<div id="divUploadContainer" style="margin-top: 0px;border: solid 1px #CCCCCC;height: 300px; width:100%;overflow: auto">
       		<?php       		
       		$data=json_decode($this->data[$uses[0]]['image']);
       		if(isset($data->FileUpload) && count($data->FileUpload)>0){
       			foreach($data->FileUpload as $k=>$v){
       				?>
       				<div id="image_<?php echo $v[0]?>" class="image" style="float:left; text-align:center; margin-top:10px;">
       				<div id="image_container" style="float:left;margin:10px">
       					<img src="<?php echo $this->webroot.'uploaded/image/thumb/'.$v[1]?>" />
       				</div>
       				<a href="javascript:;" onclick="removeImageUpload('<?php echo $v[0]?>')" >
       					<img style="float:right;margin-left:-40px;" src="<?php echo $this->webroot.'img/backend/popup-close-button.png'?>" />
       				</a>
       				<div style="clear:both"/></div>
       				<?php 
       			}
       		}
       		else{
       		?>
       		
       		
				<!-- 
					image uploaded here				
				 -->       			
       		
       		<?php }?>
       		</div>
       		<div class="fieldset flash" id="divFileProgressContainer"></div>
       		</td>           
        </tr>
        
        <tr>          
       		<td class="label" align="right" width="100px"><?php _resource('description') ?>
       		<?php if($webConfig['is_multi_lang']){?>
       		<img class="Tips1" title="<?php echo $listLang[$locale]?>" border="0" src="<?php echo $this->webroot.'img/backend/flag/'.$locale.'.png'?>">
       		<?php }?>
       		</td>
       		<td align="left"><?php echo $this->Form->textarea($uses[0].'.description',array('class'=>'','label'=>'','error'=>'','cols'=>120,'rows'=>10));?></td>           
        </tr>    
        <?php if($locale!=$this->Session->read('adminLang') && $webConfig['is_multi_lang']){?>
        	<tr>
            	<td class="label" align="right" width="100px"><?php _resource('description') ?> <img class="Tips1" title="<?php echo $listLang[$locale]?>" border="0" src="<?php echo $this->webroot.'img/backend/flag/'.$locale.'.png'?>"></td>
            	<td colspan="2"><div style="margin-top: 0px;border: solid 1px #000000;height: 300px; width:710px;overflow: auto"><?php echo $this->data[$uses[0]]['defaultdescription'] ?></div></td>
          	</tr>
        <?php }?> 
     
    
       
	</table>
    <div style="width:130px">
          <div class="button"><a onclick="onFormSubmit()" href="javascript:;" title="<?php echo _resource('save') ?>"  > <span class="icon-32-save"> </span></a> </div>         
          <div class="button"><a onclick="resetForm('adminForm')" href="javascript:;" title="<?php echo _resource('reset') ?>"  > <span class="icon-32-back"> </span></a> </div>
          <div class="button"><a onclick="closeBox('addContent','mainContent')" href="javascript:;" title="<?php echo _resource('close') ?>"  > <span class="icon-32-cancel"> </span></a> </div>
    </div>
      </form>
</fieldset>

<script>
function onFormSubmit(){
	submitForm('adminForm','addContent');
}
function removeImageUpload(imageId,prefix){
	var hiddenData=$('#<?php echo $uses[0].'Image'?>');
	$('#image_'+imageId).remove();
	var imageUploadData=$.JSON.decode(hiddenData.attr('value'));
	for(x in imageUploadData.FileUpload){
		if(imageUploadData.FileUpload[x][0]==imageId)delete imageUploadData.FileUpload[x];
	}
	hiddenData.attr('value',$.JSON.encode(imageUploadData));
	//alert(imageUploadData.26fc);
}

//for swfupload plugin
$(document).ready(function () {

	swfu = new SWFUpload({
		// Backend Settings
		upload_url: "<?php echo BACKEND_URL.'fileuploads/imageupload/image/'.$uses[0]?>",
		post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},

		// File Upload Settings
		file_size_limit : "10 MB",
		file_types : "*.jpg",
		file_types_description : "JPG Images",
		file_upload_limit : 0,

		// Event Handler Settings - these functions as defined in Handlers.js
		//  The handlers are not part of SWFUpload but are part of my website and control how
		//  my website reacts to the SWFUpload events.
		swfupload_preload_handler : preLoad,
		swfupload_load_failed_handler : loadFailed,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// Button Settings
		button_image_url : "<?php echo $this->webroot?>plugins/SWFUpload/images/SmallSpyGlassWithTransperancy_17x18.png",
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 80,
		button_height: 18,
		button_text : '<span class="button"><?php _resource('gallery') ?><br /></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		
		// Flash Settings
		flash_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload.swf",
		flash9_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload_fp9.swf",

		custom_settings : {					
			upload_target : "divFileProgressContainer",//upload status
			
			uploadContainer:"divUploadContainer",// contain upload , use for multi upload
			uploadDefaultDivThumb:'<div id="image_<<imageId>>" class="image" style="float:left; text-align:center; margin-top:10px;"><div id="image_container" style="float:left;margin:10px"></div><a href="javascript:;" onclick="removeImageUpload(\'<<imageId>>\')" ><img style="float:right;margin-left:-40px;" src="<?php echo $this->webroot.'img/backend/popup-close-button.png'?>" /></a><div style="clear:both"/></div>',//default div thumb
			DivThumbIdContainUploadImage: 'image_container',//the element id that will contain upload image in uploadDefaultInnerHtmlDivThumb
			test2ReplaceWithImageId: '<<imageId>>',//the test to replace with image id
			
			fieldInputId: "<?php echo $uses[0].'Image'?>", // target to fill upload file with this , use for single upload
			uploadType: "image-gallery", //upload type: image, doc
			numOfMaxUpload:0 //max of upload file, 1 for single, >1 for multi, 0 for unlimit
		},
		
		// Debug Settings
		debug: false
	});
});
scrollTopTo('addContent');
</script>

<?php } ?>
